@use 'modules' as *;
@forward 'widgets/views';
@forward 'widgets/buttons';
@forward 'widgets/header-bar';

// 3rd party application style fixes

// *********
// * Gedit *
// *********

.org-gnome-gedit, .gedit-side-panel-paned {
  notebook > header {
    background-color: $headerbar_bg_color;
    &:backdrop { background-color: $headerbar_backdrop_color; }
    box-shadow: inset 0 -1px $headerbar_shade_color;
  }
}

.gedit-search-slider {
  // gives gedit search entry some padding and a border
  // otherwise it's right under the headerbar
  background: $window_bg_color;
  border: 1px solid $borders_color;
  border-top-style: none;
  padding: 4px 8px;
  border-radius: 0 0 $button_radius $button_radius;

  button {
    padding-top: 7px;
    padding-bottom: 7px;
  }
}

.gedit-document-panel {
  // 'documents' pane

  background-color: $window_bg_color;

  row.activatable {
    padding: 6px;
  }

  row button {
    // 'close' button
    min-width: 22px;
    min-height: 22px;
    padding: 0;
    margin: 0;
    border: none;
  }

  row:hover button {
    &:hover {
      background-color: gtkalpha(currentColor, .15);
    }

    &:active {
      background-color: gtkalpha(currentColor, .3);
    }
  }

  row:hover:selected button:hover {
    color: $window_fg_color;
  }
}

// *********
// * XFCE4 *
// *********

.XfceHeading {
  background-color: $view_bg_color;
  margin: 0;
  padding: 0;
  border-width: 0;
}

XfdesktopIconView.view {
  background: transparent;
  color: $osd_fg_color;
  border-radius: $button_radius;
  &:active {
    background: gtkalpha(gtkmix(black, $accent_bg_color, 15%), 0.5);
    text-shadow: 0 1px 1px black;
  }
  .label { text-shadow: 1px 1px 2px black; }
  .rubberband {
    @extend rubberband;
    border-radius: 0;
  }
}

// Xfce4 panel
$panel_transition_duration: 250ms;
.xfce4-panel.background {
  border: none; 
  background-color: $panel_bg_color;
  color: $panel_fg_color;
  transition-duration: $panel_transition_duration;

  .tasklist button,
  #actions-button,
  #clock-button { margin: 0 1px; }

  &.horizontal .tasklist {
    button {
      margin: 0 1px;
      label { padding-right: 3px; }
    }
  }
  &.vertical .tasklist {
    button {
      margin: 1px 0;
      label { padding-bottom: 3px; }
    }
  }

  .tasklist image {
    //-gtk-icon-transform: scale(0); margin: -10px; // Removes the icon
    margin-left: 2px;
    margin-right: 2px;
  }

  button {
    label {
      padding-left: 6px;
      padding-right: 6px;
    }
  }

  button {
    padding: 0 6px;
    min-height: 12px;
    min-width: 12px;
    border-radius: 24px;
    color: $panel_fg_color;
    transition-duration: $panel_transition_duration;
    @include button(undecorated);

    &:disabled {
      background-color: transparent;
      color: gtkalpha($panel_fg_color, 0.2);
    }

    &:hover:not(:active):not(:checked) {
      color: $panel_fg_color;
      background-color: gtkalpha($panel_fg_color, 0.25);
      background-image: none;
    }

    &:checked {
      background-color: gtkalpha($panel_fg_color, 0.2);
      color: $panel_fg_color;

      &:hover { background-color: gtkalpha($panel_fg_color, 0.35); }

      &:disabled {
        @include button(undecorated);
        color: gtkalpha($panel_fg_color, 0.2);
      }
    }

    &:drop(active) {
      color: $accent_bg_color;
      border-color: $accent_bg_color;
      box-shadow: inset 0 0 0 1px $accent_bg_color;
    }

    entry { caret-color: $view_fg_color; }
    menu {
      -gtk-icon-effect: none;

      text-shadow: none;
      // Theme pulseaudio-plugin's mpris buttons
      .linked button {
        @extend %linked;
        @include button(normal, $popover_bg_color, $view_fg_color);
        &:disabled {
          @include button(disabled);
          border-color: gtkalpha($borders_color, $disabled_opacity);
        }
      }
    }
  }

  progressbar {
    margin: 0;

    &.horizontal {
      trough {
        min-height: 6px;
        padding: 0;
      }
      progress { min-height: 4px; }
    }

    &.vertical {
      trough {
        min-width: 6px;
        padding: 0;
      }
      progress { min-width: 4px; }
    }

    progress { border-radius: 0px; }

    trough {
      background: gtkshade($panel_bg_color, 0.7);
      border-radius: 0px;
      border-color: gtkshade($panel_bg_color, 0.4);
    }
  }
}

// Workspace switcher
wnck-pager {
  background-color: gtkalpha($panel_fg_color, 0.1);
  &:selected { background-color: gtkshade($accent_bg_color, 0.88); }
  &:hover { background-color: $accent_bg_color; }
}

// Xfwm4's alt-tab dialog, aka "tabwin"
#xfwm-tabwin {
  padding: 12px;
  border-radius: $window_radius;
  // Set the application icon- and preview-size
  -XfwmTabwinWidget-icon-size: 64px;
  -XfwmTabwinWidget-preview-size: 128px;

  .tabwin-app-grid button {
    min-width: 96px;
    min-height: 96px;
  }
}

// Whisker menu
window#whiskermenu-window {
  button { transition: none; }
}

#whiskermenu-button {
  transition: none;
}

// XfceNotifyWindow
#XfceNotifyWindow {
  border-radius: $menu_radius;
  background-color: $view_bg_color;
}

// ********
// * Nemo *
// ********

%desktop-canvas-item,
.nemo-desktop.nemo-canvas-item {
  color: $accent_fg_color;
  text-shadow: 1px 1px 2px transparentize(black, 0.2);
}

.nemo-properties-dialog {
  .dialog-action-box .dialog-action-area {
    // add margin to preferences buttons
    margin: 2px 6px 4px;
  }

  toolbar stackswitcher.linked button {
    margin-right: 0;

    &:backdrop {
      color: $backdrop_fg_color;
      background-color: $backdrop_bg_color;
    }
  }
}

.nemo-window {
  .sidebar {
    scrolledwindow.frame.nemo-places-sidebar {
      // get rid of double border in sidebar
      border: none;
    }

    viewport.frame box.vertical treeview.view.places-treeview {
      // use sidebar bg color
      background-image: image($window_bg_color);
      border-radius: 0; // get rid of weird radius on selected rows

      &:selected {
        background: $accent_bg_color;
      }

      &:not(:selected) {
        &:not(:backdrop):hover {
          $base_hover_color: gtkalpha($window_fg_color, 0.05);
          background-image: image($base_hover_color);
        }
      }
    }
  }

  .nemo-inactive-pane .view,
  .nemo-inactive-pane iconview {
    // Shades the background of the inactive pane
    background-color: $backdrop_bg_color;
  }

  .nemo-window-pane {
    widget.entry {
      // Add border around rename text entry
      border: 1px solid;
      border-radius: 3px;
      color: $window_fg_color;
      border-color: $accent_bg_color;
      background-color: $window_bg_color;
    }

    widget.entry:selected {
      // Add highlighting to selected text in rename text entry
      border: 1px solid;
      border-radius: 3px;
      color: $accent_fg_color;
      border-color: $accent_bg_color;
      background-color: $accent_bg_color;
    }
  }

  toolbar.horizontal.primary-toolbar {
    // add border under toolbar
    border-bottom: 1px solid $borders_color;

    widget.linked.raised button {
      // use proper icons for next and left in stackswitcher-like pathbar
      &:first-child widget {
        -gtk-icon-source: -gtk-icontheme('go-previous-symbolic');
      }
      &:last-child widget {
        -gtk-icon-source: -gtk-icontheme('go-next-symbolic');
      }
    }

    toolitem box widget * {
      // reset toolbar button dimensions
      min-height: 0;
      min-width: 0;
    }

    .linked button {
      // link linked buttons
      margin-right: 0;
    }
  }
}

// ***********
// * Firefox *
// ***********

#MozillaGtkWidget.background {
  // Make sure text selection is somewhat visible on websites with various backgrounds
  // One of the very few things that can still be changed in Firefox 140+
  selection {
    &:focus, & {
      background-color: $accent_bg_color;
      color: $accent_fg_color;
    }
  }
}

// ******************
// * gnome-terminal *
// ******************

terminal-window notebook > header {
  &.top,
  &.bottom {
    tabs {
      &:not(:only-child) {
        &:first-child { margin-left: 0px; }
        &:last-child { margin-right: 0px; }
      }
    }
  }
}

terminal-window notebook {
  scrollbar {
    slider {
      // Fix for Ubuntu
      // avoids scrollbar protruding from the terminal window on wayland session
      // workaround for https://bugs.launchpad.net/ubuntu/+source/gnome-terminal/+bug/1720651
      margin: 0;
      border-width: 3px;
    }
  }
}

// ********
// * Caja *
// ********

window.background.caja-navigation-window #Toolbar {
  border-bottom: 1px solid $borders_color;

  &:backdrop {
    background-color: $backdrop_bg_color;
    border-color: $backdrop_borders_color;
  }
}

.caja-pathbar button {
  min-width: 32px;
  border-radius: 0;
  border-right-width: 0;
  margin-right: -3px;

  &.slider-button:nth-child(odd) {
    border-radius: $button_radius 0px 0px $button_radius;
  }
  &.slider-button:nth-child(even) {
    border-radius: 0 $button_radius $button_radius 0;
    border-right-width: 1px;
  }
}

.caja-side-pane .frame {
  border-style: solid none none none;
}
.caja-notebook {
  .view, .view.frame, .frame {
    border-left: 0;
    border-right: 0;
  }
}

// Gets rid of fat separator on backdrop
.caja-side-pane + separator + box:backdrop {
  background: $backdrop_bg_color;
}

.caja-navigation-window,
.caja-desktop-window {
  widget.view widget.entry {
    background: gtkmix(currentColor, $window_bg_color, 5%);
    color: $window_fg_color;
    border-color: $borders_color;
  
    &:selected {
      background: $accent_bg_color;
      color: $accent_fg_color;
    }
  }
}

// desktop mode
.caja-desktop.caja-canvas-item {
  @extend %desktop-canvas-item;
}

// ************
// * GNU Cash *
// ************

#gnc-id-main-window {
  // https://github.com/lassekongo83/adw-gtk3/issues/148
  treeview.view {
    &:not(:selected):hover {
      background-color: gtkmix(currentColor, $view_bg_color, 7%);
    }
  }
}

gnc-id-sheet-list { background-color: $window_bg_color; }

// *********
// * Geary *
// *********

geary-conversation-viewer#conversation_viewer {
  list.background.conversation-listbox.content {
    background-color: $window_bg_color;
    border: none;
    border-radius: 0;

    > row.activatable {
      border: 1px solid $borders_color;
      border-bottom-width: 0;

      &:first-child {
        border-top-left-radius: $card_radius;
        border-top-right-radius: $card_radius;
      }
    }

    .geary-attachment-pane {
      border-radius: 0 0 $card_radius $card_radius;

      actionbar.background {
        background-color: transparent;

        > revealer > box {
          border-radius: 0 0 $card_radius $card_radius;
        }
      }
    }

    geary-composer-editor {
      > box.background {
        background-color: transparent;

        > actionbar > revealer > box {
          border-radius: 0 0 $card_radius $card_radius;
        }
      }
    }
  }

  searchbar {
    > revealer > box {
      background-color: $view_bg_color;
      border-color: $borders_color;
    }
  }
}

.geary-folder-popover-list-row {
  border-radius: 0;
  margin: 0;
}

// newer versions
.geary-main-window leaflet > leaflet > box {
  &:first-child {
    background-color: $sidebar_bg_color;
    &:backdrop { background-color: $sidebar_backdrop_color; }
  }
}

.geary-main-window leaflet > box {
  &:first-child > .titlebar {
    background-color: $sidebar_bg_color;
    background-image: none;
    border-bottom: transparent;
    box-shadow: none;
    &:backdrop { background-color: $sidebar_backdrop_color; }

    button {
      background-color: transparent;
      &:hover {
        background-color: $titlebutton_hover_color;
      }
      &:hover:active, &:active, &:hover:checked, &:checked  {
        background-color: $titlebutton_active_color;
      }
      &:backdrop { background: transparent; }
      &:backdrop:hover { background: $titlebutton_hover_color; }
    }
  }

  &:not(:first-child) > .titlebar {
    border-bottom: transparent;
    box-shadow: none;
    &:backdrop {
      background-image: none;
      background-color: $headerbar_bg_color;
    }
  }
}

.geary-main-window separator.sidebar {
  background-color: $borders_color;
}

.geary-main-window .titlebar .image-button {
  padding: 0 6px;
}

.geary-folder {
  .sidebar.view {
    &:selected {
      background-color: $selected_color;
      &:hover { background-color: $selected_hover_color; }
    }
    &:hover {
      background-color: $hover_color;
    }
  }
}

// ************
// * Inkscape *
// ************

#DialogNotebook treeview.view:hover {
  background-color: gtkalpha($accent_bg_color, .5);
}

// **********
// * Budgie *
// **********

.budgie-panel {
  button {
    min-height: 16px;
    min-width: 16px;
    padding: 0;
    border-radius: 0;

    &.flat.launcher {
      padding: 0;
    }
  }

  &.horizontal button,
  #tasklist-button {
    padding: 0 4px;
  }

  &.vertical button {
    padding: 4px 0;
  }

  &.vertical #tasklist-button {
    min-height: 32px;
  }
}

// **************
// Libre-Office *
// **************

// https://github.com/lassekongo83/adw-gtk3/issues/286
toolbar.toolbar {
  box:not(.linked) > button {
    font-weight: normal;
  }
}

window.background:not(.solid-csd):not(.csd) > notebook > header {
  // For libreoffice. No idea why.
  border: 0;
  tab {
    margin: 0 1px;
    // https://github.com/lassekongo83/adw-gtk3/issues/262#issuecomment-2849406909
    border-radius: $button_radius;
    box-shadow: none;
    &:hover { background-color: $hover_color; }
    &:active, &:checked { background-color: $selected_color; }
    &:checked:hover { background-color: $selected_hover_color; }
  }
}

window.background:not(.solid-csd):not(.csd) > notebook > stack:not(:only-child) {
  background-color: $window_bg_color;
}

// ***********
// Xournal++ *
// ***********

#settingsDialog .dialog-vbox.vertical tab {
  box-shadow: none;
  margin-right: 8px;
  border-radius: $button_radius;

  &:hover {
    @include button(hover);
  }

  &:checked {
    @include button(active);
  }
}
